<template>
  <div>
    <div>
      List: <span v-for="li in list" :key="li">{{li}}</span>
    </div>
    <div>
      obj: <span v-for="(v, k) in obj" :key="k">{{k}}---{{v}}</span>
    </div>
    <div>
      处理后的list和obj：
      <br>
      <div>
        List2: <span v-for="li in list2" :key="li">{{li}}</span>
      </div>
      <div>
        obj2: <span v-for="(v, k) in obj2" :key="k">{{k}}---{{v}}</span>
      </div>
    </div>
    <div>
      异步请求初始化的list和obj：
      <br>
      <div>
        ListInit: <span v-for="li in listInit" :key="li">{{li}}</span>
      </div>
      <div>
        objInit: <span v-for="(v, k) in objInit" :key="k">{{k}}---{{v}}</span>
      </div>
      <button @click="log">输出ObjInit和ListInit的值</button>
    </div>
  </div>
</template>

<script>
  export default {
    name: "son",
    props: {
      list: [],
      obj: {},
      listAsync: [],
      objAsync: {}
    },
    data() {
      return {
        list2: this.list,
        obj2: this.obj,
        listInit: [],
        objInit: {}
      }
    },
    watch: {
      listAsync: {
        handler(val) {
          console.log(val, 'listInit');
          this.listInit = val;
        },
        immediate: true
      },
      objAsync: {
        handler(val) {
          console.log(val, 'objInit');
          this.objInit = val;
        },
        immediate: true
      }
    },
    methods: {
      log() {
        console.log(this.objInit, this.listInit);
      }
    }
  }
</script>

<style scoped>

</style>
